import {Component, ViewEncapsulation} from '@angular/core';
import {FormBuilder} from '@angular/forms';
import {UserService} from '../../../services/app.user';
import {AuthenticationHelper} from "../../../app.authentication";
import {Router} from '@angular/router';
import {BaThemeSpinner}  from '../../../theme/services';

@Component({
    selector: 'feed',
    encapsulation: ViewEncapsulation.None,
    styleUrls: ['./feed.scss'],
    templateUrl: './feed.html'
})
export class Feed {

   // public profileImagelocal:any = "http://144.214.55.144:3001";
 //  public profileImagelocal:any = "http://localhost:3001";
    public profileImagelocal:any = 'http://45.79.103.182:5002';
    public feed:Array<Object>;
    public submitted:any;
    public profileServer:any;

    constructor(private fb:FormBuilder, private userService:UserService, private router:Router, private authentication:AuthenticationHelper, private spinner:BaThemeSpinner) {

    }

    ngOnInit() {
        // Function call for get recent user
        this.getRecentUsersForDash();
    }

    // API call for get recent user data
    public getRecentUsersForDash() {
        this.userService.getRecentUsers({}).subscribe(
            data => this.userDashSucces(data),
            error => this.userDashFail(error)
        );
    }
    
    // function call for get recent user data successfully
    private userDashSucces(stats) {
        this.submitted = false;
        this.feed = stats;
        this.profileServer = this.profileImagelocal;
    }

    // function call for get recent user data failed
    private userDashFail(error) {
        this.submitted = false;
        this.spinner.hideProgress();
    }
}
